package com.crm.marketing.controller;

import com.crm.common.pojo.Plan;
import com.crm.global.exception.ExceptionEnum;
import com.crm.global.result.Message;
import com.crm.marketing.service.PlanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/plan")
@Api(tags = "开发计划")
public class PlanController {

    @Autowired
    private PlanService planService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "chanceId",value = "销售机会id",required = true),
            @ApiImplicitParam(name = "planContent",value = "计划内容",required = true)
    })
    @ApiOperation("制定计划")
    @GetMapping("/draw")
    public ResponseEntity<Message<String>> drawPlan(Long chanceId, String planContent) {
        Plan plan = new Plan();
        plan.setChanceId(chanceId);
        plan.setTodo(planContent);
        planService.saveOrUpdate(plan);
        return ResponseEntity.ok(new Message<>(ExceptionEnum.SUCCESS));
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "planId",value = "开发计划id",required = true),
            @ApiImplicitParam(name = "result",value = "计划结果",required = true)
    })
    @ApiOperation("更新计划")
    @GetMapping("/update")
    public ResponseEntity<Message> updatePlan(Long planId,String result) {
        Plan plan = planService.findById(planId);
        plan.setResult(result);
        planService.saveOrUpdate(plan);
        return ResponseEntity.ok(new Message<>(ExceptionEnum.SUCCESS));
    }


    @ApiImplicitParam(name = "planId",value = "开发计划id",required = true)
    @GetMapping("/findBId")
    @ApiOperation("查找计划")
    public ResponseEntity<Message> findById(Long planId) {
        return ResponseEntity.ok(new Message<>(ExceptionEnum.SUCCESS,planService.findById(planId)));
    }
}
